package algorithm.exam.queue;

import java.util.PriorityQueue;

public class kthSmallest {

    public int kthSmallest(int[][] matrix, int k) {

        PriorityQueue<Integer> priorityQueue =new PriorityQueue<>((x,y)->x-y);
        int lena=matrix.length;
        int lenb=matrix[0].length;
        for(int i=0;i<lena;i++){
            for(int j=0;j<lenb;j++){
                priorityQueue.add(matrix[i][j]);
            }
        }

        for(int c=0;c<k;c++){
           int d= priorityQueue.poll();
           if(c==k-1){
               return d;
           }

        }

        return 0;
    }
}
